package com.fanghuaman.product.controller;

import com.fanghuaman.model.category.dto.CategoryPageDto;
import com.fanghuaman.model.common.vo.ResponseResult;
import com.fanghuaman.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author shiminghui
 * @date 2025/2/11 16:48
 * @description: TODO
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 查询所有分类
     *
     * @return
     */
    @GetMapping("/list/all")
    public ResponseResult listAll() {
        return categoryService.listAll();
    }

    /**
     * 分页查询
     *
     * @param categoryPageDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody CategoryPageDto categoryPageDto) {
        return categoryService.list(categoryPageDto);
    }

    /**
     * 根据父级id查询子级分类
     *
     * @param parentId
     * @return
     */
    @GetMapping("/get/parent/{parentId}")
    public ResponseResult get(@PathVariable("parentId") Long parentId) {
        return categoryService.getByParentId(parentId);
    }
}
